<?php
namespace app\api\controller\m2979\auto;

use think\Db;
use service\ApiReturn;
use app\api\controller\Base;
use app\member\service\MemberCache;


class Freeshubiao extends Base {
                
/**
 *  查询鼠标
 *@param  String[字符串]  aid  ID
 *@create_time  2023-12-06 11:49:14
 */ 
public function get_shubiao($data = [], $user = [])
{
    $headLang  = request()->header('lang');
    $where = [];
  
    $order = 'freeshubiao.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freeshubiao.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freeshubiao.is_del', '=', 0]; 
 	if (!empty($data['aid'])) {
		$where[] = ['freeshubiao.aid', '=', $data['aid']]; 
 	}

    $select_info = array (
  'xuanxiang' => 
  array (
    1 => 'A',
    2 => 'B',
    3 => 'C',
  ),
'member_user' => MemberCache::getUserListToMemberID(MemberID), 
'member_dept' => MemberCache::getDeptListToMemberID(MemberID),
);
 	p($select_info);
	$dataList = Db::table('lb_free_shubiao')
		->alias('freeshubiao')
		->field("freeshubiao.wenben,freeshubiao.lianxiren,freeshubiao.shipin,freeshubiao.yinle,freeshubiao.xuanxiang,freeshubiao.bumen")
		->where($where)
		->order($order)
		->select();
	foreach ($dataList as &$infodataList){
			$infodataList['lianxiren_name'] = $select_info['member_user']["{$infodataList['lianxiren']}"] ?? '';
			$infodataList['shipin']  = [get_file_url($infodataList['shipin'])];
			$infodataList['yinle']  = get_file_url($infodataList['yinle']);
			$infodataList['xuanxiang_name'] = $select_info['xuanxiang']["{$infodataList['xuanxiang']}"] ?? '';
//			$infodataList['bumen_name'] = $select_info['member_dept']["{$infodataList['bumen']}"] ?? '';
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}
                
/**
 *  操作鼠标
 *@param  String[字符串]  aid  ID
 *@create_time  2023-12-06 11:48:17
 */ 
public function set_shubiao($data = [], $user = [])
{
    $return_data = [];
    Db::startTrans();
    try {
        		//查询鼠标
		$order = 'freeshubiao.create_time desc';
		$where = [];
		$where[] = ['freeshubiao.is_del', '=', 0]; 
 		if (isset($data['aid'])) {
		$where[] = ['freeshubiao.aid', '=', $data['aid']]; 
 		}
		$query_0 = Db::table('lb_free_shubiao')
		->alias('freeshubiao')
		->where($where)
		->order($order)
		->find();
		if (!($query_0)) {
			throw new \Exception('错误',-1);
		}
		//更新鼠标
		$where = [];
		$where[] = ['is_del', '=', 0]; 
 		if (isset($data['aid'])) {
		$where[] = ['aid', '=', $data['aid']]; 
 		}
		$param=[];
		$param['wenben']= 123;
		$param['update_time'] = time();

		$query_1 = $param;
		$table_name = 'lb_free_shubiao';
		$primary_key = 'aid';
		$res = Db::table($table_name)->where($where)->update($param);
		if (!($res)) {
			throw new \Exception('错误',-1);
		}


        
        

        Db::commit();
        
        
    }
    catch (\Exception $e){
        Db::rollback();
        $msg = $e->getMessage();
        $code = $e->getCode();
        return ApiReturn::r($code, [], $msg);
    }

    return ApiReturn::r(1, $return_data, '请求成功');
}

}